<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>
    // 根据月份判断本月有几天
    var month = 4;
    var str = '';
    switch(month){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:str = "31天";break;
        case 4:
        case 11:
        case 6:
        case 9:str = "30天";break;
        case 2:str = "28天";break;
    }
    console.log(str);


    // =========


    var year = 2024;
    var month = 12;
    var d = 31;

    // 准备容器，用来存储天数
    var sum = 0;
    // 利用了switch的case穿透，配合累加运算，计算结果
    switch(month){
        case 12:sum += 30;
        case 11:sum += 31;
        case 10:sum = sum + 30;
        case 9:sum = sum + 31;
        case 8:sum = sum + 31;
        case 7:sum = sum + 30;
        case 6:sum = sum + 31;
        case 5:sum = sum + 30;
        case 4:sum = sum + 31;
        case 3:
            if(year%4 === 0 && year%100 !== 0 || year%400 === 0){
                sum = sum + 29;
            }else{
                sum = sum + 28;
            }
        case 2:sum = sum + 31;
        case 1:sum = sum + d;
    }
    // 打印结果
    console.log(year + "年" + month + "月" + d + "日是这一年的第" + sum + "天");

</script>
</html>